import { createRouter, createWebHistory, RouteRecordRaw } from "vue-router";
import { routerRole } from '../api/fun'
import Layout from '@/layout/index.vue'

const routes: Array<RouteRecordRaw> = [
  {
    path: '/', redirect: '/home',name: 'init',component:Layout,children: [
        { path: '/home', name:'putong', component: () => import('../view/putong.vue') },
        { path: '/index',name:'index', component:() => import('../view/index.vue') },
        { path: '/zujian',name:'zujian',component: () => import('../view/router-view.vue'),children:[] }
    ]
  },
];

const role = 'admin'

const router = createRouter({
  history: createWebHistory(),
  routes,
});
const adminRouter  = [{
  path: 'admin' , name:'admin', component: () =>  import('../view/admin.vue')
}, {path: 'nothing', name: 'nothing', component: () => import('../view/nothing.vue')}]
const endrouter = [{
  path: '/:pathMatch(.*)*', component: () => import('../view/404.vue')
}]

// if(role === 'admin') {
//   routerRole(adminRouter,router,'zujian')
//   routerRole(endrouter,router, 'zujian')
// } else {
//   routerRole(endrouter,router, 'zujian')
// }

// console.log(router.hasRoute('admin'));
// console.log(router.getRoutes())
router.onError(info => {
  console.log("error", info);
} )

export default router;
